package com.xyht.sca_s.student_manage_system.modules.common.controller;


import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import com.xyht.sca_s.student_manage_system.common.annotation.RepeatRequestCheck;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonCodeEnum;
import com.xyht.sca_s.student_manage_system.common.commonReturn.CommonResult;
import com.xyht.sca_s.student_manage_system.common.commonReturn.ResponseResult;
import com.xyht.sca_s.student_manage_system.modules.common.service.SmsFileUpDownService;
import io.swagger.annotations.ApiModelProperty;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.util.concurrent.Future;

/**
 * <p>
 * 文件上传下载
 * </p>
 *
 * @author XYHT
 * @since 2022-11-29
 */
@RestController
@RequestMapping("/file")
@Log4j2
public class SmsFileUpDownController {
    @Autowired
    private SmsFileUpDownService smsFileUpDownService;

    @PostMapping("/upload")
    @RepeatRequestCheck(name = "fileUpload")
    public ResponseResult fileUpload(@RequestParam("file") MultipartFile file) {
        return smsFileUpDownService.fileUpload(file);
    }

    @ApiModelProperty(value = "用户头像上传")
    @PostMapping("/userPicUpload")
    public ResponseResult userPicUpload(@RequestParam("file") MultipartFile file) {
        return smsFileUpDownService.userPicUpload(file);
    }

    @ApiModelProperty(value = "oss上传")
    @PostMapping("/aliyunFileUpload")
    public ResponseResult aliyunFileUpload(@RequestParam("file") MultipartFile multipartFile) {
        return smsFileUpDownService.aliyunFileUpload(multipartFile);
    }

    @GetMapping("/download")
    public ResponseResult fileDownload(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        return smsFileUpDownService.fileDownload(fileName, response);
    }
    @GetMapping("/waterMarkDownload")
    public ResponseResult waterMarkDownload(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        return smsFileUpDownService.waterMarkDownload(fileName, response);
    }

    @GetMapping("/moduleDownload")
    public ResponseResult moduleDownload(@RequestParam("fileName") String fileName, HttpServletResponse response) {
        return smsFileUpDownService.moduleDownload(fileName, response);
    }


}

